@include('admin.layout.bone_header')

<div class="layui-btn-container">


</div>


<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">
    @{{# if(d['status'] == 0) { }}
    <a class="layui-btn layui-btn-xs" lay-event="recharge">审核</a>
    @{{# } }}

</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.withs.withs')}}", [
            {field: 'withdrawal_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'nums', title: '数量'}
            , {field: 'fee', title: '手续费'}
            , {field: 'type', title: '类型',templet:function (d){
                    if(d['shop_id'] != 0){
                        return '商家提现';
                    }else if(d['user_id'] != 0){
                        return  '用户提现';
                    }
                }}
            , {field: 'json', title: '银行卡号',templet:function (d){
                    let jsonArr = JSON.parse(d['card_json_data']);
                    return jsonArr['card_no'];
                }}
            , {field: 'json', title: '银行',templet:function (d){
                    let jsonArr = JSON.parse(d['card_json_data']);
                    return jsonArr['card_kai'];
                }}
            , {field: 'json', title: '姓名',templet:function (d){
                    let jsonArr = JSON.parse(d['card_json_data']);
                    return jsonArr['name'];
                }}
            , {field: 'json', title: '状态',templet:function (d){
                let arr = ['未审核','通过','拒绝'];
                    return arr[d['status']];
                }}
            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'recharge') {
                layer.confirm('是否审核通过？', {
                    closeBtn: 2,
                    btn: ['确认', '拒绝'] //可以无限个按钮
                }, function(index, layero){
                    //按钮【按钮一】的回调
                    console.log('点击同意按钮')
                    HttpUtils.post('{{route('admin.withs.confirm')}}',{
                        status:1,
                        withdrawal_id:data['withdrawal_id']
                    },function (res){
                        if(res['code'] != 200){
                            Utils.errorToast(res['msg'])
                            return;
                        }
                        layer.close(index)
                        layui.table.reload("think-table");
                    });
                }, function(index){
                    //按钮【按钮二】的回调
                    HttpUtils.post('{{route('admin.withs.confirm')}}',{
                        status:2,
                        withdrawal_id:data['withdrawal_id']
                    },function (res){
                        if(res['code'] != 200){
                            Utils.errorToast(res['msg'])
                            return;
                        }
                        layer.close(index)
                        layui.table.reload("think-table");
                    });

                });
            }else if(obj.event === 'set_shop'){
                UI.openLayer("{{route('admin.users.set_shop')}}?user_id="+data['user_id'],1080);
            }
        });
        let $ = layui.$, active = {

        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
